package com.lhy.service.impl;

import com.lhy.dao.DoctorAdviceDao;
import com.lhy.dao.DoctorDao;
import com.lhy.domain.DoctorAdvice;
import com.lhy.domain.Doctors;
import com.lhy.service.DoctorAdviceService;
import com.lhy.utils.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 汪
 */
@Service
public class DoctorAdviceServiceImpl implements DoctorAdviceService {
    @Autowired
    DoctorAdviceDao doctorAdviceDao;
    @Autowired
    DoctorDao doctorDao;
    @Override
    public List<DoctorAdvice> showAllAdvice() {
        List<DoctorAdvice> advices= doctorAdviceDao.showAllAdvice();
        for (DoctorAdvice advice : advices) {
            Doctors doctorById = null;
            try {
                doctorById = doctorDao.getDoctorById(advice.getDocid());
            } catch (Exception e) {
                e.printStackTrace();
            }
            advice.setDocname(doctorById.getName());
        }
        return advices;
    }

    @Override
    public void addAdvice(DoctorAdvice doctorAdvice) {
        doctorAdviceDao.addAdvice(doctorAdvice);
    }

    @Override
    public void deleteAdvice(Integer daid) {
        doctorAdviceDao.deleteAdvice(daid);
    }

    @Override
    public List<DoctorAdvice> findSomeAdvice(Pagination<DoctorAdvice> page) {
        List<DoctorAdvice> advices= doctorAdviceDao.findSomeAdvice(page);
        for (DoctorAdvice advice : advices) {
            Doctors doctorById = null;
            try {
                doctorById = doctorDao.getDoctorById(advice.getDocid());
            } catch (Exception e) {
                e.printStackTrace();
            }
            advice.setDocname(doctorById.getName());
        }
        return advices;
    }
}
